package de.mmis.core.base.abstracttree.serializer;

import java.util.Map;

import de.mmis.core.base.abstracttree.Tree;

/**
 * Interface representing an conversion class serializing an object in a
 * {@link Tree} and deserializing (vice versa)
 * 
 * @author Christian Koch
 * 
 * @param <T>
 *            type of objects that can be (de)serialized
 */
public interface Serializer<T> {
	/**
	 * Serialize a given Object in a {@link Tree}. The serialization must be
	 * human-readable, i.e., it should be a string-representation of the object.
	 * Please note that serialize and deserialize must be dual in the sense that
	 * deserializing a serialized object must yield a copy of the original
	 * object.
	 * 
	 * @param object
	 *            The object to be serialized in a {@link Tree}.
	 * @param explicit
	 *            if set to <code>true</code>, the serialization will be done
	 *            explicitly. This means it can be deserialized even if the
	 *            target type is unknown
	 * @param refmap
	 *            map storing the references to previously serialized objects.
	 *            This is used to resolve self-references and avoid infinite
	 *            recursive serialization
	 * @return a {@link Tree} with the serialized version of the object
	 */
	public abstract Tree serialize(T object, boolean explicit,
			Map<Object, String> refmap, ClassLoader classLoader);
}
